<template>
	<view style="overflow: hidden;">
		<view style="background-color: #FFFFFF;padding:60upx;overflow: hidden;">
			<view style="font-size:24px;font-weight: bold;">输入顾客信息</view>
			<view style="color:#666666;margin-bottom:20px;">填写顾客信息，获取更加精准的测试结果</view>
			<view class="weui-cells guest weui-noline weui-cells__form">
				<view class="weui-cell weui-noline">
					<view class="weui-cell__hd"><text class="weui-label">手机号</text></view>
					<view class="weui-cell__bd weui-cell__primary">
						<input class="weui-input" placeholder="请输入手机号" @input="changeMobile" v-model="formInfo.mobile"
							:maxlength="13" />
					</view>
				</view>
				<view style="margin-top:30px;">
					<button @click="moNext" class="weui-btn_primary"
						:class="nextActive ? '':'weui-btn_disabled'" Data-btnname="下一步">下一步</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>

	export default {
		components: {
		
		},
		data() {
			return {
				nextActive:false,
				maxlength:11,
				formInfo: {
					mobile: ""
				}
			}
		},
		onLoad(e) {
			
			
			this.$users.checkLogin();
		},
		onShow() {
			let _this = this;
			_this.handleSugoioLoad('输入顾客手机号', 'guest-mobile')
		},
		methods: {
			changeMobile(e) {
				var len = this.formInfo.mobile.length;
				var trimLen = this.formInfo.mobile.replace(/\s+/g, "").length;
				var kong = this.formInfo.mobile.match(/ /g);
				if (!this.$filters.isEmpty(kong)) {
					if (kong.length == 1) {
						this.maxlength = 12;
					} else if (kong.length == 2) {
						this.maxlength = 13;
					}
				} else {
					this.maxlength = 11;
				}

				if (len == 3 || len == 8) {
					this.formInfo.mobile = this.formInfo.mobile + " ";
				} else if (len == 4 && trimLen == 4) {
					this.formInfo.mobile = this.formInfo.mobile.substring(0, 3) + " " + this.formInfo.mobile.substring(3,
						4);
				} else if (len == 9 && trimLen == 8) {
					this.formInfo.mobile = this.formInfo.mobile.substring(0, 8) + " " + this.formInfo.mobile.substring(8,
						9);
				}
				var regPhone = (/^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/); //手机号码
				var phone = this.formInfo.mobile.replace(/\s+/g, "");
				if (phone.length == 11 &&
					regPhone.test(phone)) {
					this.nextActive = true;
				} else {
					this.nextActive = false;
				}
			},
			moNext() {
				if (!this.nextActive) {
					this.$common.toast((this.formInfo.mobile == '' ? "请输入手机号" : "请输入正确的手机号"));
					return;
				}
				this.$common.to("guest-add?mobile=" + this.formInfo.mobile.replace(/\s+/g, ""));
			}
		}
	}
</script>


<style lang="scss">
	.guest .weui-cell {
		background-color: #f9f9f9;
		border-radius: 100px;
		margin-bottom: 20px;
		padding: 8px 20px;
	}
</style>
